package co.edu.usbcali.presentation.businessDelegate;

import co.edu.usbcali.parcial3.Comprobante;
import co.edu.usbcali.parcial3.Factura;
import co.edu.usbcali.parcial3.FacturaPaga;
import co.edu.usbcali.parcial3.Usuario;
import co.edu.usbcali.parcial3.control.ComprobanteLogic;
import co.edu.usbcali.parcial3.control.FacturaLogic;
import co.edu.usbcali.parcial3.control.FacturaPagaLogic;
import co.edu.usbcali.parcial3.control.IComprobanteLogic;
import co.edu.usbcali.parcial3.control.IFacturaLogic;
import co.edu.usbcali.parcial3.control.IFacturaPagaLogic;
import co.edu.usbcali.parcial3.control.IUsuarioLogic;
import co.edu.usbcali.parcial3.control.UsuarioLogic;

import java.math.BigDecimal;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * Use a Business Delegate to reduce coupling between presentation-tier clients
 * and business services. The Business Delegate hides the underlying
 * implementation details of the business service, such as lookup and access
 * details of the EJB architecture.
 * 
 * The Business Delegate acts as a client-side business abstraction; it provides
 * an abstraction for, and thus hides, the implementation of the business
 * services. Using a Business Delegate reduces the coupling between
 * presentation-tier clients and the system's business services. Depending on
 * the implementation strategy, the Business Delegate may shield clients from
 * possible volatility in the implementation of the business service API.
 * Potentially, this reduces the number of changes that must be made to the
 * presentation-tier client code when the business service API or its underlying
 * implementation changes.
 * 
 * However, interface methods in the Business Delegate may still require
 * modification if the underlying business service API changes. Admittedly,
 * though, it is more likely that changes will be made to the business service
 * rather than to the Business Delegate.
 * 
 * Often, developers are skeptical when a design goal such as abstracting the
 * business layer causes additional upfront work in return for future gains.
 * However, using this pattern or its strategies results in only a small amount
 * of additional upfront work and provides considerable benefits. The main
 * benefit is hiding the details of the underlying service. For example, the
 * client can become transparent to naming and lookup services. The Business
 * Delegate also handles the exceptions from the business services, such as
 * java.rmi.Remote exceptions, Java Messages Service (JMS) exceptions and so on.
 * The Business Delegate may intercept such service level exceptions and
 * generate application level exceptions instead. Application level exceptions
 * are easier to handle by the clients, and may be user friendly. The Business
 * Delegate may also transparently perform any retry or recovery operations
 * necessary in the event of a service failure without exposing the client to
 * the problem until it is determined that the problem is not resolvable. These
 * gains present a compelling reason to use the pattern.
 * 
 * Another benefit is that the delegate may cache results and references to
 * remote business services. Caching can significantly improve performance,
 * because it limits unnecessary and potentially costly round trips over the
 * network.
 * 
 * A Business Delegate uses a component called the Lookup Service. The Lookup
 * Service is responsible for hiding the underlying implementation details of
 * the business service lookup code. The Lookup Service may be written as part
 * of the Delegate, but we recommend that it be implemented as a separate
 * component, as outlined in the Service Locator pattern (See "Service Locator"
 * on page 368.)
 * 
 * When the Business Delegate is used with a Session Facade, typically there is
 * a one-to-one relationship between the two. This one-to-one relationship
 * exists because logic that might have been encapsulated in a Business Delegate
 * relating to its interaction with multiple business services (creating a
 * one-to-many relationship) will often be factored back into a Session Facade.
 * 
 * Finally, it should be noted that this pattern could be used to reduce
 * coupling between other tiers, not simply the presentation and the business
 * tiers.
 * 
 * @author Zathura Code Generator http://code.google.com/p/zathura
 * 
 */
public class BusinessDelegatorView {
	private BusinessDelegatorView() {
	}

	public static List<Comprobante> getComprobante() throws Exception {
		IComprobanteLogic comprobanteLogic = new ComprobanteLogic();

		return comprobanteLogic.getComprobante();
	}

	// Metodo que consulta los comprobantes del usuario que esta en la sesion...
	public static List<Comprobante> getComprobanteSesion(String cod)
			throws Exception {
		IComprobanteLogic comprobanteLogic = new ComprobanteLogic();
		return comprobanteLogic.getComprobanteSesion(cod);
	}

	public static void saveComprobante(String comCodigo, Date comFechaPago,
			Long comValorPagado, String usuCodigo_Usuario) throws Exception {
		IComprobanteLogic comprobanteLogic = new ComprobanteLogic();
		comprobanteLogic.saveComprobante(comCodigo, comFechaPago,
				comValorPagado, usuCodigo_Usuario);
	}

	public static void deleteComprobante(String comCodigo) throws Exception {
		IComprobanteLogic comprobanteLogic = new ComprobanteLogic();
		comprobanteLogic.deleteComprobante(comCodigo);
	}

	public static void updateComprobante(String comCodigo, Date comFechaPago,
			Long comValorPagado, String usuCodigo_Usuario) throws Exception {
		IComprobanteLogic comprobanteLogic = new ComprobanteLogic();
		comprobanteLogic.updateComprobante(comCodigo, comFechaPago,
				comValorPagado, usuCodigo_Usuario);
	}

	public static Comprobante getComprobante(String comCodigo) throws Exception {
		IComprobanteLogic comprobanteLogic = new ComprobanteLogic();
		Comprobante comprobante = null;

		try {
			comprobante = comprobanteLogic.getComprobante(comCodigo);
		} catch (Exception e) {
			throw e;
		}

		return comprobante;
	}

	public static List<Comprobante> findByCriteriaInComprobante(
			Object[] variables, Object[] variablesBetween,
			Object[] variablesBetweenDates) throws Exception {
		IComprobanteLogic comprobanteLogic = new ComprobanteLogic();

		return comprobanteLogic.findByCriteria(variables, variablesBetween,
				variablesBetweenDates);
	}

	public static List<Comprobante> findPageComprobante(String sortColumnName,
			boolean sortAscending, int startRow, int maxResults)
			throws Exception {
		IComprobanteLogic comprobanteLogic = new ComprobanteLogic();

		return comprobanteLogic.findPageComprobante(sortColumnName,
				sortAscending, startRow, maxResults);
	}

	public static Long findTotalNumberComprobante() throws Exception {
		IComprobanteLogic comprobanteLogic = new ComprobanteLogic();

		return comprobanteLogic.findTotalNumberComprobante();
	}

	public static List<Factura> getFactura() throws Exception {
		IFacturaLogic facturaLogic = new FacturaLogic();

		return facturaLogic.getFactura();
	}

	public static void saveFactura(Date factFechaEmision, Date factFechaLimite,
			String factNumero, Long factValor, String usuCodigo_Usuario)
			throws Exception {
		IFacturaLogic facturaLogic = new FacturaLogic();
		facturaLogic.saveFactura(factFechaEmision, factFechaLimite, factNumero,
				factValor, usuCodigo_Usuario);
	}

	public static void deleteFactura(String factNumero) throws Exception {
		IFacturaLogic facturaLogic = new FacturaLogic();
		facturaLogic.deleteFactura(factNumero);
	}

	public static void updateFactura(Date factFechaEmision,
			Date factFechaLimite, String factNumero, Long factValor,
			String usuCodigo_Usuario) throws Exception {
		IFacturaLogic facturaLogic = new FacturaLogic();
		facturaLogic.updateFactura(factFechaEmision, factFechaLimite,
				factNumero, factValor, usuCodigo_Usuario);
	}

	public static Factura getFactura(String factNumero) throws Exception {
		IFacturaLogic facturaLogic = new FacturaLogic();
		Factura factura = null;

		try {
			factura = facturaLogic.getFactura(factNumero);
		} catch (Exception e) {
			throw e;
		}

		return factura;
	}

	public static List<Factura> findByCriteriaInFactura(Object[] variables,
			Object[] variablesBetween, Object[] variablesBetweenDates)
			throws Exception {
		IFacturaLogic facturaLogic = new FacturaLogic();

		return facturaLogic.findByCriteria(variables, variablesBetween,
				variablesBetweenDates);
	}

	public static List<Factura> findPageFactura(String sortColumnName,
			boolean sortAscending, int startRow, int maxResults)
			throws Exception {
		IFacturaLogic facturaLogic = new FacturaLogic();

		return facturaLogic.findPageFactura(sortColumnName, sortAscending,
				startRow, maxResults);
	}

	public static Long findTotalNumberFactura() throws Exception {
		IFacturaLogic facturaLogic = new FacturaLogic();

		return facturaLogic.findTotalNumberFactura();
	}

	public static List<FacturaPaga> getFacturaPaga() throws Exception {
		IFacturaPagaLogic facturaPagaLogic = new FacturaPagaLogic();

		return facturaPagaLogic.getFacturaPaga();
	}

	public static void saveFacturaPaga(String factPagCodigo,
			String comCodigo_Comprobante, String factNumero_Factura)
			throws Exception {
		IFacturaPagaLogic facturaPagaLogic = new FacturaPagaLogic();
		facturaPagaLogic.saveFacturaPaga(factPagCodigo, comCodigo_Comprobante,
				factNumero_Factura);
	}

	public static void deleteFacturaPaga(String factPagCodigo) throws Exception {
		IFacturaPagaLogic facturaPagaLogic = new FacturaPagaLogic();
		facturaPagaLogic.deleteFacturaPaga(factPagCodigo);
	}

	public static void updateFacturaPaga(String factPagCodigo,
			String comCodigo_Comprobante, String factNumero_Factura)
			throws Exception {
		IFacturaPagaLogic facturaPagaLogic = new FacturaPagaLogic();
		facturaPagaLogic.updateFacturaPaga(factPagCodigo,
				comCodigo_Comprobante, factNumero_Factura);
	}

	public static FacturaPaga getFacturaPaga(String factPagCodigo)
			throws Exception {
		IFacturaPagaLogic facturaPagaLogic = new FacturaPagaLogic();
		FacturaPaga facturaPaga = null;

		try {
			facturaPaga = facturaPagaLogic.getFacturaPaga(factPagCodigo);
		} catch (Exception e) {
			throw e;
		}

		return facturaPaga;
	}

	public static List<FacturaPaga> findByCriteriaInFacturaPaga(
			Object[] variables, Object[] variablesBetween,
			Object[] variablesBetweenDates) throws Exception {
		IFacturaPagaLogic facturaPagaLogic = new FacturaPagaLogic();

		return facturaPagaLogic.findByCriteria(variables, variablesBetween,
				variablesBetweenDates);
	}

	public static List<FacturaPaga> findPageFacturaPaga(String sortColumnName,
			boolean sortAscending, int startRow, int maxResults)
			throws Exception {
		IFacturaPagaLogic facturaPagaLogic = new FacturaPagaLogic();

		return facturaPagaLogic.findPageFacturaPaga(sortColumnName,
				sortAscending, startRow, maxResults);
	}

	public static Long findTotalNumberFacturaPaga() throws Exception {
		IFacturaPagaLogic facturaPagaLogic = new FacturaPagaLogic();

		return facturaPagaLogic.findTotalNumberFacturaPaga();
	}

	public static List<Usuario> getUsuario() throws Exception {
		IUsuarioLogic usuarioLogic = new UsuarioLogic();

		return usuarioLogic.getUsuario();
	}

	public static void saveUsuario(String usuCodigo, String usuContrasena,
			String usuUsuario) throws Exception {
		IUsuarioLogic usuarioLogic = new UsuarioLogic();
		usuarioLogic.saveUsuario(usuCodigo, usuContrasena, usuUsuario);
	}

	public static void deleteUsuario(String usuCodigo) throws Exception {
		IUsuarioLogic usuarioLogic = new UsuarioLogic();
		usuarioLogic.deleteUsuario(usuCodigo);
	}

	public static void updateUsuario(String usuCodigo, String usuContrasena,
			String usuUsuario) throws Exception {
		IUsuarioLogic usuarioLogic = new UsuarioLogic();
		usuarioLogic.updateUsuario(usuCodigo, usuContrasena, usuUsuario);
	}

	public static Usuario getUsuario(String usuCodigo) throws Exception {
		IUsuarioLogic usuarioLogic = new UsuarioLogic();
		Usuario usuario = null;

		try {
			usuario = usuarioLogic.getUsuario(usuCodigo);
		} catch (Exception e) {
			throw e;
		}

		return usuario;
	}

	public static List<Usuario> findByCriteriaInUsuario(Object[] variables,
			Object[] variablesBetween, Object[] variablesBetweenDates)
			throws Exception {
		IUsuarioLogic usuarioLogic = new UsuarioLogic();

		return usuarioLogic.findByCriteria(variables, variablesBetween,
				variablesBetweenDates);
	}

	public static List<Usuario> findPageUsuario(String sortColumnName,
			boolean sortAscending, int startRow, int maxResults)
			throws Exception {
		IUsuarioLogic usuarioLogic = new UsuarioLogic();

		return usuarioLogic.findPageUsuario(sortColumnName, sortAscending,
				startRow, maxResults);
	}

	public static Long findTotalNumberUsuario() throws Exception {
		IUsuarioLogic usuarioLogic = new UsuarioLogic();

		return usuarioLogic.findTotalNumberUsuario();
	}

	public static List<Usuario> getUsuario2(String usu, String pass)
			throws Exception {
		IUsuarioLogic usuLogic = new UsuarioLogic();
		return usuLogic.getUsuario2(usu, pass);
	}

	// Metodo que consulta las facturas pagadas por codigo de comprobante....
	public static List<FacturaPaga> getFacturaPagaCodigo(String codCompro)
			throws Exception {
		IFacturaPagaLogic facturaPagaLogic = new FacturaPagaLogic();
		return facturaPagaLogic.getFacturaPagaCodigo(codCompro);
	}

	public static List<Factura> getFacturaPorPagar(String codigo)
			throws Exception {
		try {
			IFacturaLogic facturaLogic = new FacturaLogic();
			return facturaLogic.getFacturaPorPagar(codigo);
		} catch (Exception e) {
			throw e;
		}
	}
}
